/* 
 * Enterprise Library Extensions - DI + ORM.
 * Copyright (C) 2006
 *
 * GNU General Public License
 *
 * This program is free software; you can redistribute 
 * it and/or modify it under the terms of the GNU General Public License 
 * as published by the Free Software Foundation; either version 2 of the 
 * License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful, but 
 * WITHOUT ANY WARRANTY; without even the implied warranty of 
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. 
 * See the GNU General Public License for more details.
 */
using System;
using System.Text;
namespace ELE.EnterpriseLibrary.Naming
{
  /// <summary>
  /// This is the superclass of all exceptions thrown by operations in the Context and DirContext interfaces. The nature of the failure is described by the name of the subclass. This exception captures the information pinpointing where the operation failed, such as where resolution last proceeded to. 
  ///   
  /// <list type="bullet">
  /// <item>      
  /// <term>Resolved Name</term>
  /// <description>Portion of name that has been resolved</description>
  /// </item>
  /// <item>
  /// <term>Resolved Object</term>
  /// <description>Object to which resolution of name proceeded</description>
  /// </item>
  /// <item>
  /// <term>Remaining Name</term>
  /// <description>Portion of name that has not been resolved</description>
  /// </item>
  /// <item>
  /// <term>Explanation</term>
  /// <description>Detail explaining why name resolution failed</description>
  /// </item>
  /// <item>
  /// <term>Root Exception</term>
  /// <description>The exception that caused this naming exception to be thrown</description>
  /// </item>
  /// </list>
  ///  null is an acceptable value for any of these fields. When null, it means that no such information has been recorded for that field.  
  /// </summary>
  public class NamingException: ApplicationException
  {
    /// <summary>
    /// Contains the remaining name that has not been resolved yet
    /// </summary>
    protected IName remainingName;
    /// <summary>
    /// Contains the part of the name that has been successfully resolved
    /// </summary>
    protected IName resolvedName;
    /// <summary>
    /// Contains the object to which resolution of the part of the name was successful.
    /// </summary>
    protected object resolvedObject;
    /// <summary>
    ///  Contains the original exception that caused this NamingException to be thrown
    /// </summary>
    protected Exception rootException;
    /// <summary>
    /// public accessor of remainingName
    /// </summary>
    public IName RemainingName
    {
      get
      {
        return remainingName;
      }
      set
      {
        remainingName = value;
      }
    }
    /// <summary>
    /// public accessor of resolvedName
    /// </summary>
    public IName ResolvedName
    {
      get
      {
        return resolvedName;
      }
      set
      {
        resolvedName = value;
      }
    }
    /// <summary>
    /// public accessor of resolvedObject
    /// </summary>
    public object ResolvedObject
    {
      get
      {
        return resolvedObject;
      }
      set
      {
        resolvedObject = value;
      }
    }
    /// <summary>
    /// public accessor of rootException
    /// </summary>
    public Exception RootCause
    {
      get
      {
        return rootException;
      }
      set
      {
        rootException = value;
      }
    }
    /// <summary>
    /// A formatted message about the exception
    /// </summary>
    public string Explanation
    {
      get
      {
        StringBuilder sb = new StringBuilder();
        sb.Append("Naming exception caught while resolving object from named context");
        sb.Append(" : The resolved name is ").Append(ResolvedName.ToString());
        sb.Append(" : The remaining name is ").Append(RemainingName.ToString());
        sb.Append(" : The resolved object is ").Append(ResolvedObject.ToString());
        return sb.ToString();
      }
    }
    /// <summary>
    /// Constructs a new NamingException
    /// </summary>
    public NamingException()
    {
    }
    /// <summary>
    /// Constructs a new NamingException with an explanation
    /// </summary>
    /// <param name="message">explanation</param>
    public NamingException(string message): base(message)
    {
    }
    /// <summary>
    /// Constructs a new NamingException with an explanation and inner exception
    /// </summary>
    /// <param name="message"></param>
    /// <param name="inner"></param>
    public NamingException(string message, Exception inner): base(message, inner)
    {
    }
    
  }
}
